{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from skopt import BayesSearchCV\n",
    "from skopt.space import Real, Categorical, Integer\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.model_selection import KFold\n",
    "from sklearn.ensemble import GradientBoostingRegressor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "data = pd.read_csv('C:/datacastle/shengwu/data.csv')\n",
    "data= data[data['Ki']> -11].fillna(-999)\n",
    "X_scale= data.drop('Ki',axis=1)\n",
    "\n",
    "\n",
    "\n",
    "X_scale = data.drop('Protein_ID',axis=1)\n",
    "\n",
    "\n",
    "\n",
    "X_scale = data.drop('Molecule_ID',axis=1)\n",
    "X=X_scale\n",
    "y2=data['Ki']\n",
    "model = GradientBoostingRegressor(\n",
    "     loss='ls',\n",
    "     learning_rate = 0.0035,\n",
    "     max_depth=23,\n",
    "     n_estimators=30275,\n",
    "     max_features=9,\n",
    "     min_samples_leaf=22,\n",
    "     min_samples_split=15,\n",
    "     min_weight_fraction_leaf=0.0102470171519909\n",
    ")\n",
    "\n",
    "search_params = {\n",
    "     \"n_estimators\": Integer(1000, 4000),\n",
    "     'max_depth': Integer(2, 40),\n",
    "     'min_samples_split': Integer(2, 15),\n",
    "     'min_samples_leaf': Integer(2, 50),\n",
    "     'min_weight_fraction_leaf': Real(0., .5),\n",
    "     'max_features': Integer(2, 13)\n",
    "}\n",
    "\n",
    "opt = BayesSearchCV(model, search_params, n_iter=50, n_jobs=-1, )\n",
    "opt.fit(X_scale, y2)\n",
    "opt.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
